'use strict';
var jwt = require('jsonwebtoken');
module.exports = app => {
  class authController extends app.Controller {
    * login(ctx) {
        let body=ctx.request.body;
        var user=yield ctx.model.Admin.findOne({where:{userName:body.userName,passWord:body.passWord}});
        if(user){
            var token=jwt.sign({
                exp: Math.floor(Date.now() / 1000) + (60 * 60),
                data: {
                    admin:{
                        id:user.id
                    }
                }
            }, ctx.locals.tokenScrect);
            ctx.body={token:token};
        }
    }
  }
  return authController;
};
